package com.grace.web.controller.cms;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.grace.common.annotation.Log;
import com.grace.common.core.controller.BaseController;
import com.grace.common.core.domain.AjaxResult;
import com.grace.common.enums.BusinessType;
import com.grace.common.enums.OperateTitle;
import com.grace.common.utils.poi.ExcelUtil;
import com.grace.cms.admin.service.ICmsUpdateService;
import com.grace.cms.common.domain.entity.CmsUpdate;
import com.grace.common.core.page.TableDataInfo;

/**
 * 内容更新Controller
 * 
 * @author grace
 * @date 2025-08-16
 */
@RestController
@RequestMapping("/cms/update")
public class CmsUpdateController extends BaseController
{
    @Autowired
    private ICmsUpdateService cmsUpdateService;

    /**
     * 查询内容更新列表
     */
    @PreAuthorize("@ss.hasPermi('system:update:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsUpdate cmsUpdate)
    {
        startPage();
        List<CmsUpdate> list = cmsUpdateService.selectCmsUpdateList(cmsUpdate);
        return getDataTable(list);
    }

    /**
     * 导出内容更新列表
     */
    @PreAuthorize("@ss.hasPermi('system:update:export')")
    @Log(title = OperateTitle.CMS_UPDATE, businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsUpdate cmsUpdate)
    {
        List<CmsUpdate> list = cmsUpdateService.selectCmsUpdateList(cmsUpdate);
        ExcelUtil<CmsUpdate> util = new ExcelUtil<CmsUpdate>(CmsUpdate.class);
        util.exportExcel(response, list, "内容更新数据");
    }

    /**
     * 获取内容更新详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:update:query')")
    @GetMapping(value = "/{updateId}")
    public AjaxResult getInfo(@PathVariable("updateId") Long updateId)
    {
        return success(cmsUpdateService.selectCmsUpdateByUpdateId(updateId));
    }

    /**
     * 删除内容更新
     */
    @PreAuthorize("@ss.hasPermi('system:update:remove')")
    @Log(title = OperateTitle.CMS_UPDATE, businessType = BusinessType.DELETE)
	@DeleteMapping("/{updateIds}")
    public AjaxResult remove(@PathVariable("updateIds") Long[] updateIds)
    {
        return toAjax(cmsUpdateService.deleteCmsUpdateByUpdateIds(updateIds));
    }
}
